package com.zyg.manager.controller;

import com.alibaba.fastjson.JSONObject;
import com.zyg.manager.entity.ContentEntity;
import com.zyg.manager.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping
public class IndexController {
    @Autowired
    ContentService contentService;
    //默认页面
    @GetMapping({"/","/index.html"})
    public String index(Model model, HttpSession session){
        //1.1 查询广告
        List<ContentEntity> list = contentService.findAll();
        //得到session中的数据
        JSONObject user = (JSONObject) session.getAttribute("user");
        System.out.println("user = " + user);
        //存放到model中
        model.addAttribute("user",user);
        //放到model中
        model.addAttribute("contentList",list);
        return "index"; //物理视图: /templates/index.html
    }
}
